<?php
/**
 * 专家账户管理
 */
function expertmanage_create_page(){
	  //我们为这个页面设置标题
	 drupal_set_title('专家信息管理');
	 global $user;  
	 
	 $query = "SELECT id FROM " .
           "{expert_info} where userid = ?";
 	 $queryResult = db_query($query, array($user->uid));
	 $ifempty =TRUE;
	 $pageid ='';
	  foreach ($queryResult as $links ) {
	  	$pageid =$links->id;
	  	if($pageid > 0)
		  	$ifempty = FALSE;
	  }
	 if($ifempty)
	 {
	 	 $render_array = array(
	   		'#markup' => '',
		 );
	 
		 //该页面的正文为一个表单，注意对于表单，这里需要使用drupal_render呈现一下。
		 $form = drupal_get_form('expertmanage_create_form');
		 $render_array['#markup'] .= drupal_render($form);
	 }
	 else{
	 	 $render_array = array(
	   		'#markup' => '',
		 );
	 
		$form = drupal_get_form('expertmanage_edit_form',$pageid);
  		$render_array['#markup'] .= drupal_render($form);
	 }	 
	 //Drupal7的页面回调，返回的应该是一个数组
	 return $render_array;
}

function expertmanage_create_form(){	 
	  //提示信息，默认为markup类型。
	 $form['tips'] = array(
	  '#prefix' =>'<div id="tips">',
	  '#markup' => t('<span class="form-required">*</span> 号为必填项。'),
	  '#suffix' =>'</div>',
	 );
	 
	 //表单元素“姓名”
	 $form['name'] = array(
	   //表单元素的#title属性，对应于实际输出中的label
	  '#title' => t('姓名'),
	  //表单元素的类型，这里为textfield
	  '#type' => 'textfield',
	  //这个表单元素是必填的
	  '#required' => TRUE,
	  //表单元素的默认值，这里使用了三位运算符和isset进行判定
	  '#default_value' =>isset($_SESSION['expertmanage_create_form']['name'])?$_SESSION['expertmanage_create_form']['name']:"",
	  //表单元素的描述，
	 );
	 
	 $form['education'] = array(
	  '#title' => t('学历'),
	  '#type' => 'textfield',
	  '#required' => TRUE,
	  '#default_value' =>isset($_SESSION['expertmanage_create_form']['education'])?$_SESSION['expertmanage_create_form']['education']:"",
	 );
	 
	 $form['phone'] = array(
	  '#title' => t('联系电话'),
	  '#type' => 'textfield',
	  '#required' => TRUE,
	  '#default_value' =>isset($_SESSION['expertmanage_create_form']['phone'])?$_SESSION['expertmanage_create_form']['phone']:"",
	 );
	 
	  $form['mail'] = array(
	  '#title' => t('邮箱地址'),
	  '#type' => 'textfield',
	  '#required' => TRUE,
	  '#default_value' =>isset($_SESSION['expertmanage_create_form']['mail'])?$_SESSION['expertmanage_create_form']['mail']:"",
	 );
	 
	  $form['position'] = array(
	  '#title' => t('职位'),
	  '#type' => 'textfield',
	  '#required' => TRUE,
	  '#default_value' =>isset($_SESSION['expertmanage_create_form']['position'])?$_SESSION['expertmanage_create_form']['position']:"",
	 );
	 
	 $form['research_area'] = array(
	  '#title' => t('研究领域'),
	  '#type' => 'textarea',
	  '#required' => FALSE,
	  '#default_value' =>isset($_SESSION['expertmanage_create_form']['research_area'])?$_SESSION['expertmanage_create_form']['research_area']:"",
	 );
	 	 
	 $form['achievements'] = array(
	  '#title' => t('个人成果'),
	  '#type' => 'textarea',
	  '#required' => FALSE,
	  '#default_value' =>isset($_SESSION['expertmanage_create_form']['achievements'])?$_SESSION['expertmanage_create_form']['achievements']:"",
	 );
	 	 
	 $form['submit'] = array(
	    '#type' => 'submit',
	    '#value' => t('确认'),
	 );
	  return $form;
}

function expertmanage_create_form_validate($form, &$form_state){
	 if(!preg_match("/^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/", $form_state['values']['mail'])){
	  form_set_error('mail',t('您输入的电子邮件地址格式不正确'));
	 }
	  if (drupal_strlen($form_state['values']['name']) < 2) {
	    form_set_error('name', '您输入的姓名长度太短，请填写真实姓名。');
	  }
  
}

function expertmanage_create_form_submit($form, &$form_state){
	  //把表单的值存放在会话中去，由于这里涉及到了两个不同的表单之间传值。
	 $_SESSION['expertmanage_create_form'] = $form_state['values'];
	 //表单重定向到确认页面
	 $form_state['redirect'] = 'expertmanage/create/confirm';
}

function expertmanage_confirm_page(){
  //我们为这个页面设置标题
	 drupal_set_title('提交专家信息预览');
	 
	 //这里首先作了判断，如果会话中没有设置contactus_form，返回contactus
	 if(empty($_SESSION['expertmanage_create_form'])){
	  drupal_goto('expertmanage/create');
	 }
	 $render_array = array(
	   '#markup' => '', 
	 );
	 //该页面的正文为一个表单，注意对于表单，这里需要使用drupal_render呈现一下。
	 $form = drupal_get_form('expertmanage_confirm_form');
	 $render_array['#markup'] .= drupal_render($form);
	 //Drupal7的页面回调，返回的应该是一个数组
	 return $render_array;
}

function expertmanage_confirm_form(){
 $form['name'] = array(
  '#title' => t('姓名'),
  '#type' => 'item',
  '#markup' => isset($_SESSION['expertmanage_create_form']['name'])?$_SESSION['expertmanage_create_form']['name']:"",
 );
 
 $form['education'] = array(
  '#title' => t('学历'),
  '#type' => 'item',
  '#markup' => isset($_SESSION['expertmanage_create_form']['education'])?$_SESSION['expertmanage_create_form']['education']:"",
 );
 
 $form['phone'] = array(
  '#title' => t('联系电话'),
  '#type' => 'item',
  '#markup' => isset($_SESSION['expertmanage_create_form']['phone'])?$_SESSION['expertmanage_create_form']['phone']:"",
 );
 
 $form['mail'] = array(
  '#title' => t('邮箱地址'),
  '#type' => 'item',
  '#markup' => isset($_SESSION['expertmanage_create_form']['mail'])?$_SESSION['expertmanage_create_form']['mail']:"",
 );
 
 $form['position'] = array(
  '#title' => t('职位'),
  '#type' => 'item',
  '#markup' => isset($_SESSION['expertmanage_create_form']['position'])?$_SESSION['expertmanage_create_form']['position']:"",
 );
 
 $form['research_area'] = array(
  '#title' => t('研究邻域'),
  '#type' => 'item',
  '#markup' => isset($_SESSION['expertmanage_create_form']['research_area'])?$_SESSION['expertmanage_create_form']['research_area']:"",
 );
 
 $form['achievements'] = array(
  '#title' => t('个人成果'),
  '#type' => 'item',
  '#markup' => isset($_SESSION['expertmanage_create_form']['achievements'])?$_SESSION['expertmanage_create_form']['achievements']:"",
 );
  
  $form['back'] = array(
    '#type' => 'submit',
    '#value' => t('返回'),
    '#submit' => array('expertmanage_confirm_form_back'),
  );

  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('提交'),
  );
  
  return $form;
}

function expertmanage_confirm_form_back($form, &$form_state){
  //简单的重定向到contactus页面
 $form_state['redirect'] = 'expertmanage/create';
}

function expertmanage_confirm_form_submit($form, &$form_state){
		/**
	   * 写入数据库
	   */
	   $values = NULL;
	   //从会话中获取用户最初提交的值，并将$_SESSION['contactus_form']置为空。
	  if(empty($_SESSION['expertmanage_create_form'])){
		  //drupal_goto('contact');
		  $form_state['redirect'] = 'expertmanage/create';
	  }else{
		  $values = $_SESSION['expertmanage_create_form'];
		  unset($_SESSION['expertmanage_create_form']);
	  }
	  global $user;
	  $last_id = db_insert('expert_info')
  		->fields(array(
  		     'userid'=> $user->uid,
   			 'education' => $values['education'],
   			 'name' => $values['name'],
   			 'phone' => $values['phone'],
   			 'mail' => $values['mail'],
   			 'position' =>  $values['position'],
   			 'research_area' =>  $values['research_area'],
   			 'achievements' => $values['achievements'],
  			))->execute();
	  if ($last_id!=NULL) {
	    
	    /**
	     * 执行成功了，到数据库去看看，是不是有这条记录了
	     * 显示一条信息给用户
	     */
		 $form_state['redirect'] = 'expertmanage/edit/'.$last_id;
		 	    
	  } else {
	    
	    // 数据写入失败了
	    drupal_set_message('抱歉，遇到问题，提交失败了', 'error');
	    
	  }
		
	
}

function expertmanage_list_page() {
 $header = array(
      array('data' => '姓名', 'field' => 'name', 'sort' => 'desc'),
      array('data' => '职务', 'field' => 'position'),
      array('data' => '电话', 'field' => 'phone'),
      array('data' => '邮箱', 'field' => 'mail'),
      array('data' => '学历', 'field' => 'education'),
      );
  $query = db_select('expert_info', 'n')
      ->extend('PagerDefault') //Pager Extender
      ->limit(15)//10 results per page
      ->extend('TableSort')//Sorting Extender
      ->orderByHeader($header)//Field to sort on is picked from $header
      ->fields ('n', array (
      'id',
      'name',
      'position',
      'phone',
      'mail',
      'education',
      ));
  $results = $query
      ->execute();

  $rows = array();
  foreach ($results as $node) {
      $rows[] = array(
      'data' => array(
        l($node->name, 'expertmanage/edit/'. $node->id),
        $node->position,
        $node->phone,
        $node->mail,
        $node->education,
      )
      );
  }
  $html = theme('table', 
      array(
            'header' => $header,
            'rows'=>$rows,
            //'caption' => '反馈意见列表',//Optional Caption for the table
            'sticky' => TRUE,//Optional to indicate whether the table headers should be sticky
            'empty' => '没有专家信息',//Optional empty text for the table if resultset is empty
      )
      );
  $html .= theme('pager',
      array(
            'tags' => array()
      )
      );
  return ($html); 
}

function expertmanage_list_perpage($perid) {
  // content variable that will be returned for display
  $page_content = '';
  $page_content .= l('查看专家信息列表','expertmanage/list') . '<br />'. '<br />';
  
  $query = "SELECT name,education,phone,mail,position,research_area,achievements FROM " .
           "{expert_info} where id = ?";
  $queryResult = db_query($query, array($perid));
  foreach ($queryResult as $links ) { 
    $page_content .= '<h5>姓名：'.$links->name.'</h5><br />';
	$page_content .= '<h5>学历：'.$links->education.'</h5><br />';
	$page_content .= '<h5>联系电话：'.$links->phone.'</h5><br />';
	$page_content .= '<h5>邮箱地址：'.$links->mail.'</h5><br />';
	$page_content .= '<h5>职务'.$links->position.'</h5><br />';
    $page_content .= '<h5>研究领域：'.$links->research_area.'</h5><br />';
    $page_content .= '<h5>个人成果：'.$links->achievements.'</h5><br />';
	$page_content = str_replace(array("\n", "\r\n") , "<BR />", $page_content);
  }
  // More coming....
  if ($page_content == '') {
    $page_content = "没有该专家信息.";
  }

  return $page_content;
}

function expertmanage_edit_page($perid) {
  $page_content = '';
  if(user_access('view experts information'))
  	$page_content .= l('查看专家信息列表','expertmanage/list') . '<br />'. '<br />';
  drupal_set_title('专家信息管理');
	 
	 $query = "SELECT id FROM " .
           "{expert_info} where id = ?";
 	 $queryResult = db_query($query, array($perid));
	 $ifempty =TRUE;
	  foreach ($queryResult as $links ) {
	  	if($links->id>0)
		  	$ifempty = FALSE;
	  }
	 if($ifempty)
	 {
	 	 $render_array = array(
	   		'#markup' => '',
		 );
	 
		 //该页面的正文为一个表单，注意对于表单，这里需要使用drupal_render呈现一下。
		 $form = drupal_get_form('expertmanage_create_form');
		 $render_array['#markup'] .= drupal_render($form);
	 }
	 else{
	 	 $render_array = array(
	   		'#markup' => $page_content,
		 );
	 
		$form = drupal_get_form('expertmanage_edit_form',$perid);
  		$render_array['#markup'] .= drupal_render($form);
	 }	 
	 //Drupal7的页面回调，返回的应该是一个数组
	 return $render_array;
}

function expertmanage_edit_form($form, &$form_state, $perid){
  
  $query = "SELECT name,education,phone,mail,position,research_area,achievements FROM " .
           "{expert_info} where id = ?";
  $queryResult = db_query($query, array($perid));
 
  $name = '';
  $education = '';
  $phone = '';
  $mail = ''; 
  $position = '';
  $research_area = '';
  $achievements = '';
  
  foreach ($queryResult as $links ) {
  	$name = $links->name;
    $education = $links->education;
	$phone = $links->phone;
    $mail = $links->mail;
	$position = $links->position;
	$research_area = $links->research_area;
    $achievements = $links->achievements;
  }
   $form['bid'] = array('#type' => 'hidden', '#value' => $perid);
   $form['name'] = array(
	  '#title' => t('姓名'),
	  '#type' => 'textfield',
	  '#required' => TRUE,
	  '#default_value' =>isset($_SESSION['expertmanage_edit_form']['name'])?$_SESSION['expertmanage_edit_form']['name']:$name,
	 );
	 
	 $form['education'] = array(
	  '#title' => t('学历'),
	  '#type' => 'textfield',
	  '#required' => TRUE,
	  '#default_value' =>isset($_SESSION['expertmanage_edit_form']['education'])?$_SESSION['expertmanage_edit_form']['education']:$education,
	 );
	 
      $form['phone'] = array(
	  '#title' => t('联系电话'),
	  '#type' => 'textfield',
	  '#required' => TRUE,
	  '#default_value' =>isset($_SESSION['expertmanage_edit_form']['phone'])?$_SESSION['expertmanage_edit_form']['phone']:$phone,
	 );
  	 
	 $form['mail'] = array(
	  '#title' => t('邮箱地址'),
	  '#type' => 'textfield',
	  '#required' => TRUE,
	  '#default_value' =>isset($_SESSION['expertmanage_edit_form']['mail'])?$_SESSION['expertmanage_edit_form']['mail']:$mail,
	 );
	 
	 $form['position'] = array(
	  '#title' => t('职务'),
	  '#type' => 'textfield',
	  '#required' => TRUE,
	  '#default_value' =>isset($_SESSION['expertmanage_edit_form']['position'])?$_SESSION['expertmanage_edit_form']['position']:$position,
	 );
	 
	 $form['research_area'] = array(
	  '#title' => t('研究领域'),
	  '#type' => 'textarea',
	  '#required' => TRUE,
	  '#default_value' =>isset($_SESSION['expertmanage_edit_form']['research_area'])?$_SESSION['expertmanage_edit_form']['research_area']:$research_area,
	 );
	 
	 $form['achievements'] = array(
	  '#title' => t('个人成果'),
	  '#type' => 'textarea',
	  '#required' => TRUE,
	  '#default_value' =>isset($_SESSION['expertmanage_edit_form']['achievements'])?$_SESSION['expertmanage_edit_form']['achievements']:$achievements,
	 );
	
	  $form['submit'] = array(
	    '#type' => 'submit',
	    '#value' => t('提交修改'),
	  );
	 //表单元素“提交”按钮
	  $form['deleate'] = array(
	    '#type' => 'submit',
	    '#value' => t('删除专家信息'),
	    '#submit' => array('expertmanage_edit_form_deleate'),
	  );
  return $form;
}

function expertmanage_edit_form_submit($form, &$form_state){
	  $values = NULL;
	  $values = $form_state['values'];		
	  db_update('expert_info')
  		->fields(array(
   			 'education' => $values['education'],
   			 'name' => $values['name'],
   			 'phone' => $values['phone'],
   			 'mail' => $values['mail'],
   			 'position' =>  $values['position'],
   			 'research_area' =>  $values['research_area'],
   			 'achievements' => $values['achievements'],
  			))
  		->condition('id', $values['bid'])
  		->execute();
	 $form_state['redirect'] = 'expertmanage/edit/'.$values['bid'];
}

function expertmanage_edit_form_deleate($form, &$form_state){
	 $values = NULL;
	 $_SESSION['expertmanage_edit_form'] = $form_state['values'];
	 $values = $_SESSION['expertmanage_edit_form'] ;
	 //表单重定向到确认页面
	 $form_state['redirect'] = 'expertmanage/deleate/'.$values['bid'];
}

function expertmanage_deleate_page($perid) {
  // content variable that will be returned for display
  $page_content = '删除后专家信息将不可恢复！';
  
  drupal_set_title('删除专家信息');
	 
	 $render_array = array(
	   '#markup' => $page_content,
	 );
	 
	 //该页面的正文为一个表单，注意对于表单，这里需要使用drupal_render呈现一下。
	 $form = drupal_get_form('expertmanage_deleate_form');
	 $render_array['#markup'] .= drupal_render($form);
	 
	 //Drupal7的页面回调，返回的应该是一个数组
  return $render_array;

}

function expertmanage_deleate_form($form, &$form_state){
 //表单元素“返回”按钮
  $form['back'] = array(
    '#type' => 'submit',
    '#value' => t('取消'),
    '#submit' => array('expertmanage_deleate_form_back'),
  );
 //表单元素“提交”按钮
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('删除'),
  );
  
  return $form;
}

function expertmanage_deleate_form_back($form, &$form_state){
	if(empty($_SESSION['expertmanage_edit_form'])){
		  if(user_access('view experts information'))
		  	$form_state['redirect'] = 'expertmanage/list';
		  else{
		  	$form_state['redirect'] = 'expertmanage/create';
		  }
	  }else{
		  $values = $_SESSION['expertmanage_edit_form'];
		  unset($_SESSION['expertmanage_edit_form']);
		  $form_state['redirect'] = 'expertmanage/edit/'.$values['bid'];
	  }
}

function expertmanage_deleate_form_submit($form, &$form_state){
  //简单的重定向到contactus页面
 if(empty($_SESSION['expertmanage_edit_form'])){
		  //drupal_goto('contact');
		   if(user_access('view experts information'))
		  	$form_state['redirect'] = 'expertmanage/list';
		  else{
		  	$form_state['redirect'] = 'expertmanage/create';
		  }
	  }else{
		  $values = $_SESSION['expertmanage_edit_form'];
		  unset($_SESSION['expertmanage_edit_form']);
		  db_delete('expert_info')
			->condition('id' ,$values['bid'])
			->execute();
		  if(user_access('view experts information'))
		  	$form_state['redirect'] = 'expertmanage/list';
		  else
		  	$form_state['redirect'] = 'expertmanage/create';
	  }

}

function expertmanage_choose_page($fund_id) {
  drupal_set_title('专家选择管理');
  $page_content = '';
  $page_content .= l('返回基金列表','guidingfund/guidingfund_expertchoose_page') . '<br />'. '<br />';
  $query = "SELECT id, name FROM " .
           "{guiding_fund_info} where id = ?";
  $queryResult = db_query($query, array($fund_id));
  foreach($queryResult as $result){
  	$page_content .= '当前基金：' . '&nbsp;&nbsp;'. $result->name.'<br><br>';
  }
  //该页面的正文为一个表单，注意对于表单，这里需要使用drupal_render呈现一下。
  $render_array = array(
  		'#markup' => $page_content,
  );
  $form = drupal_get_form('expertmanage_choose_form', $fund_id);
  $render_array['#markup'] .= drupal_render($form ); 
  
  return $render_array; 
}

function expertmanage_choose_form($form, &$form_state, $perid){
  $query = "SELECT experts_list FROM " .
           "{guiding_fund_info} where id = ?";
  $experts_list = db_query($query, array($perid));	
  $experts = array();
  foreach ($experts_list as $expert) {
      $experts = explode(',',$expert->experts_list);
  }
  $query = "SELECT id,name, position,phone,mail, education FROM " .
           "{expert_info}";
  $queryResult = db_query($query);	
  
  $header = array(
    'name' => t('姓名'),
    'position' => t('职务'),
    'phone' => t('电话'),
    'mail' => t('邮箱'),
    'education' => t('学历'),
    'state' => t('状态(空表示未被选择)'),
  );
  $options = array();
  foreach ($queryResult as $node) {
  	$state = '';
  	if(in_array($node->id,$experts, TRUE)&&$experts!=NULL){
  		$state=  '已选择';
  	}
    $options[$node->id] =array(
      'name' => l($node->name, 'expertmanage/list/'. $node->id),
      'position' => $node->position,
      'phone' => $node->phone,
      'mail' => $node->mail,
      'education' => $node->education,  
      'state' => $state,   
    );
  }
  $form['bid'] = array('#type' => 'hidden', '#value' => $perid);
  $form['table'] = array(
    '#type' => 'tableselect',
    '#header' => $header,
    '#options' => $options,
    '#empty' => t('没有专家记录'),
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('提交'),
  );
  return $form;  
}

function expertmanage_choose_form_submit($form, &$form_state){
	 $values = NULL;
	 $values = $form_state['values'];		
	 $experts_list = '';
	 foreach ($values['table'] as $rows) {
         $experts_list.=$rows.',';
     }
	  db_update('guiding_fund_info')
  		->fields(array(
   			 'experts_list' => $experts_list,
  			))
  		->condition('id', $values['bid'])
  		->execute();
	 $form_state['redirect'] = 'expertmanage/choose/'.$values['bid'];	
	 
}
///////
//专家评分模块
///////

function expertmanage_graded_list_page() {
 $html = ''; 
 global $user;
 $query = "SELECT id FROM " .
           "{expert_info} where userid = ?";
 $experts_list = db_query($query, array($user->uid));	
 $current_expertid = '';
 foreach ($experts_list as $expert) {
      $current_expertid = $expert->id;
  }		   
 if($current_expertid > 0){
 	$header = array(
      array('data' => '基金名称', 'field' => 'name', 'sort' => 'desc'),
      array('data' => '负责人', 'field' => 'principal_name'),
      array('data' => '电话', 'field' => 'phone'),
      array('data' => '邮箱', 'field' => 'mail'),
      array('data' => '成立时间', 'field' => 'timestamp'),
      array('data' => '评分', 'field' => 'expert_graded'),
      );
  
  $query = db_select('guiding_fund_info', 'n')
      ->extend('PagerDefault') //Pager Extender
      ->limit(15)//10 results per page
      ->extend('TableSort')//Sorting Extender
      ->orderByHeader($header)//Field to sort on is picked from $header
      ->fields ('n', array (
      'id',
      'name',
      'principal_name',
      'phone',
      'mail',
      'timestamp',
      'experts_list',
      ));
  $results = $query
      ->execute();

  $rows = array();
  foreach ($results as $node) {
      $experts = explode(',',$node->experts_list);
	  $title = '';
	  if(in_array($current_expertid,$experts, TRUE)&&$experts!=NULL){
	  	$title = l('进入评审', 'expertmanage/graded/'.$node->id);	  
	  $rows[] = array(
	      'data' => array(
	        l($node->name, 'guidingfund/list/'. $node->id),
	        $node->principal_name,
	        $node->phone,
	        $node->mail,
	        format_date($node->timestamp, 'custom', 'D, Y-m-d'),
	        $title,
	      )
	  );
	  	  }
  }
  
  $html .= theme('table', 
      array(
            'header' => $header,
            'rows'=>$rows,
            //'caption' => '反馈意见列表',//Optional Caption for the table
            'sticky' => TRUE,//Optional to indicate whether the table headers should be sticky
            'empty' => '没有需要评分的基金信息',//Optional empty text for the table if resultset is empty
      )
      );
  $html .= theme('pager',
      array(
            'tags' => array()
      )
      );
 }		   
 else{
  $html .= l('请填写专家信息！','expertmanage/create');
 }
  return ($html); 
}

//专家编辑打分
//传人基金id
function expertmanage_graded_perpage($guiding_fund_id){

 $html = l('返回基金列表','expertmanage/graded/list') . '<br />'. '<br />'; 
 $query = "SELECT id, name FROM " .
           "{guiding_fund_info} where id = ?";
  $queryResult = db_query($query, array($guiding_fund_id));
  foreach($queryResult as $result){
  	$html .= '当前基金：' . '&nbsp;&nbsp;'. $result->name.'<br><br>';
  }
 $header = array(
      array('data' => '申报人名称', 'field' => 'apply_name', 'sort' => 'desc'),
      array('data' => '管理机构得分', 'field' => 'score_department'),
      array('data' => '发起人得分', 'field' => 'score_applyman'),
      array('data' => '运营方案得分', 'field' => 'score_schema'),
      array('data' => '评分时间', 'field' => 'timestamp'),
      array('data' => '评分操作', 'field' => 'setscore'),
      );
  $query = "SELECT to_graded_list FROM " .
           "{guiding_fund_info} where id = ?";
  $company_list = db_query($query, array($guiding_fund_id));	
  $companys = array();
  foreach ($company_list as $company) {
      $companys = explode(',',$company->to_graded_list);
  }
  
  $query = db_select('apply_file_info', 'n')
      ->extend('PagerDefault') //Pager Extender
      ->limit(15)//10 results per page
      ->extend('TableSort')//Sorting Extender
      ->orderByHeader($header)//Field to sort on is picked from $header
      ->fields ('n', array (
      'id',
      'apply_name',
      ))
	  ->condition('guiding_fund_id', $guiding_fund_id,'=')
	  ->condition('type', 1,'=')
	  ;
  $results = $query
      ->execute();
  global $user;
  $rows = array();
  foreach ($results as $node) {
  	if(in_array($node->id,$companys, TRUE)&&$companys!=NULL){
         $query = "SELECT id, apply_id, score_department, score_applyman, score_schema,timestamp FROM " .
           "{expert_verdict} where apply_id = ? and expert_info_id =?";
		 $verdict_list = db_query($query, array($node->id, $user->uid));	
		 $current_verdictid = '';
		 $current_score_department = '';
		 $current_score_applyman = '';
		 $current_score_schema = '';
		 $current_timestamp = '';
		 foreach ($verdict_list as $verdict) {
		      $current_verdictid = $verdict->id;
			  $current_score_department = $verdict->score_department;
		 	  $current_score_applyman = $verdict->score_applyman;
		 	  $current_score_schema = $verdict->score_schema;
		 	  $current_timestamp = $verdict->timestamp;
		  }	
		  $title = '';
		  if($current_verdictid > 0){
		  		$current_timestamp = format_date($current_timestamp, 'custom', 'D, Y-m-d');
		  }
		  else{
				$current_timestamp = "尚未评分";
		  }	
		  if(user_access('view experts information')){
		  	  $title .= l('查看评分结果','expertmanage/all_graded_fund_view/'.$node->id) ; 
		  } 
		  else{
		  	  $title .= l('进入评分','expertmanage/graded_apply/'.$node->id) ; 
		  }
		  $rows[] = array(
	      'data' => array(
	        l($node->apply_name, 'applyfile/list/'. $node->id),
	        $current_score_department,
	        $current_score_applyman,
	        $current_score_schema,
	        $current_timestamp,
	        $title,
	      )
	      );
	  }
  }
  $html .= theme('table', 
      array(
            'header' => $header,
            'rows'=>$rows,
            //'caption' => '反馈意见列表',//Optional Caption for the table
            'sticky' => TRUE,//Optional to indicate whether the table headers should be sticky
            'empty' => '没有申报人信息',//Optional empty text for the table if resultset is empty
      )
      );
  $html .= theme('pager',
      array(
            'tags' => array()
      )
      );
  return ($html); 
}

function expertmanage_graded_applypage($perid) {
  $page_content = '';
  drupal_set_title('申报材料专家评分'); 
  $state = '';
  $query = "SELECT id, apply_name, name, url, state, guiding_fund_id FROM " .
           "{apply_file_info} where id = ?";
  $queryResult = db_query($query, array($perid));
  $applyid = '';
  $apply_name = '';
  $guiding_fund_id = '';
  $filename = '';
  $fileurl = '';
  foreach ($queryResult as $links ) {
	  if($links->id>0){
	  	  $applyid = $links->id;
 	  	  $apply_name = $links->apply_name;
		  $guiding_fund_id = $links->guiding_fund_id;
		  $filename = $links->name;
		  $fileurl = $links->url;
	  }  
  }
  if($applyid<0)
  {
  	drupal_goto('expertmanage/graded/'.$guiding_fund_id);
  }
  $page_content .= l('查看评分列表','expertmanage/graded/'.$guiding_fund_id) . '<br />'. '<br />';
  global $user;
  $query = "SELECT id FROM " .
           "{expert_verdict} where expert_info_id = ? and apply_id =?";
  $queryResult = db_query($query, array($user->uid, $applyid ));
  
  foreach ($queryResult as $links ) {
	if($links->id>0){
	    $page_content .= l('切换成浏览模式','expertmanage/graded_apply_view/'.$applyid) . '<br />'. '<br />'; 
	    if(!user_access('create experts information')){
	    	drupal_goto('expertmanage/graded_apply_view/'.$applyid);
	    }
    }
  }
  
  $render_array = array(
	  '#markup' => $page_content,
  );
  if(user_access('create experts information')){
  	  $form = drupal_get_form('expertmanage_graded_applyform',$perid);
  	  $render_array['#markup'] .= drupal_render($form);
  }
  else{
  	  $render_array['#markup'] .= '尚未被评分';
  }
  return $render_array;
}

function expertmanage_graded_applyform($form, &$form_state, $perid){
  $query = "SELECT id ,file_managed_id ,assess,opinion,score_department,score_applyman,score_schema,timestamp,state FROM " .
           "{expert_verdict} where expert_info_id = ? and apply_id =?";
  global $user;
  $queryResult = db_query($query, array($user->uid, $perid ));
	$assess = '';
	$opinion = '';
	$score_department = '';
	$score_applyman = '';
	$score_schema = '';
	$state = '';
	$file_managed_id = '';
	foreach ($queryResult as $links ) {
		if($links->id>0){
			$assess = $links->assess;
			$opinion = $links->opinion;
			$score_department = $links->score_department;
			$score_applyman = $links->score_applyman;
			$score_schema = $links->score_schema;
			$state = $links->state;
			$file_managed_id = $links->file_managed_id;
		}
	}		
   	$form['bid'] = array('#type' => 'hidden', '#value' => $perid);
	 
    $form['score_department'] = array(
	  '#title' => t('管理机构得分'),
	  '#type' => 'textfield',
	  '#required' => TRUE,
	  '#default_value' =>isset($_SESSION['expertmanage_graded_applyform']['score_department'])?$_SESSION['expertmanage_graded_applyform']['score_department']:$score_department,
	 );
	$form['score_applyman'] = array(
	  '#title' => t('发起人得分'),
	  '#type' => 'textfield',
	  '#required' => TRUE,
	  '#default_value' =>isset($_SESSION['expertmanage_graded_applyform']['score_applyman'])?$_SESSION['expertmanage_graded_applyform']['score_applyman']:$score_applyman,
	 );
	$form['score_schema'] = array(
	  '#title' => t('运营方案得分'),
	  '#type' => 'textfield',
	  '#required' => TRUE,
	  '#default_value' =>isset($_SESSION['expertmanage_graded_applyform']['score_schema'])?$_SESSION['expertmanage_graded_applyform']['score_schema']:$score_schema,
	 );
	 $form['assess'] = array(
	  '#title' => t('综合评价'),
	  '#type' => 'textarea',
	  '#required' => TRUE,
	  '#default_value' =>isset($_SESSION['expertmanage_graded_applyform']['assess'])?$_SESSION['expertmanage_graded_applyform']['assess']:$assess,
	 );
	  $form['opinion'] = array(
	  '#title' => t('推荐意见'),
	  '#type' => 'textarea',
	  '#required' => TRUE,
	  '#default_value' =>isset($_SESSION['expertmanage_graded_applyform']['opinion'])?$_SESSION['expertmanage_graded_applyform']['opinion']:$opinion,
	 );
	  $form['state'] = array(
	  '#title' => t('提交评分（勾选后引导基金管理人员可见评分结果）'),
	  '#type' => 'checkbox',
	  '#default_value'=>isset($_SESSION['expertmanage_graded_applyform']['state'])?$_SESSION['expertmanage_graded_applyform']['state']:$state,
	
	  );
	 
	 if($file_managed_id>0){
	 	 $form['upload'] = array(
		  '#type' => 'managed_file',
		  '#title' => '重新提交审批回复材料',
		  '#required' => FAlSE,
		  '#upload_location' => 'public://my_uploads',
		  '#upload_validators' => array(
		    'file_validate_extensions' => array('doc xls pdf docx xlsx'),
			'file_validate_size' => array(20*1024*1024)),
		);
	 }
	 else{
	 	 $form['upload'] = array(
		  '#type' => 'managed_file',
		  '#title' => '提交审批回复材料',
		  '#required' => FAlSE,
		  '#upload_location' => 'public://my_uploads',
		  '#upload_validators' => array(
		    'file_validate_extensions' => array('doc xls pdf docx xlsx'),
			'file_validate_size' => array(20*1024*1024)),
		);
	 }	
	 
	 
	 $form['submit'] = array(
	    '#type' => 'submit',
	    '#value' => t('提交审批'),
	  );	
	
  return $form;
}

function expertmanage_graded_applyform_submit($form, &$form_state){
	$values=$form_state['values'];	
	$fid = $form_state['values']['upload']; 
	$filename = '';
	$file = file_load($fid);  	
	global $user; 
    $query = "SELECT id ,file_managed_id  FROM " .
           "{expert_verdict} where expert_info_id = ? and apply_id =?";
    global $user;
    $queryResult = db_query($query, array($user->uid, $values['bid'] ));
    $verdictid = '';  //
	foreach ($queryResult as $links ) {
		if($links->id>0){
			$verdictid = $links->id;
	        if($links->file_managed_id>0){
	        	$file = file_load($links->file_managed_id);
				  if($file!=NULL){
					 file_delete($file);
				  }
				db_delete('file_managed')
					->condition('fid',$links->file_managed_id)
					->execute();			
			}
		}
	}
	//得到专家姓名
	$query = "SELECT id ,name  FROM " .
           "{expert_info} where userid = ?";
    $queryResult = db_query($query, array($user->uid ));
    $expertname = '';
	foreach ($queryResult as $links ) {
		if($links->id>0){
			$expertname = $links->name;
		}
	}
	//得到基金id
	$query = "SELECT id ,guiding_fund_id  FROM " .
           "{apply_file_info} where id = ?";
    $queryResult = db_query($query, array($values['bid']));
    $guiding_fund_id = '';
	foreach ($queryResult as $links ) {
		if($links->id>0){
			$guiding_fund_id = $links->guiding_fund_id;
		}
	}
		
	if ($file != null) {
		$saveurl = file_uri_target($file->uri);
		$fid = $file->fid;   
		//$extension_errors=file_validate_extensions($file, "jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp docx");   
	    $extension_errors=file_validate_extensions($file, "doc xls pdf docx xlsx");   
		if (!$extension_errors) {  
			$file->status = FILE_STATUS_PERMANENT;   
			file_save($file);
           if($verdictid>0){
			db_update('expert_verdict')
			  ->fields(array(
			   	'filename' => $expertname.'_专家评审文件',
		   		'url' => $saveurl,
		   		'assess' => $values['assess'],
		   		'opinion' => $values['opinion'],
		   		'score_department' => $values['score_department'],
		   		'score_schema' => $values['score_schema'],
		   		'score_applyman' => $values['score_applyman'],
		   		'timestamp' =>  $_SERVER['REQUEST_TIME'],
		   		'file_managed_id' =>  $fid,
		   		'state' => $values['state'],
			  	))
			  ->condition('id',$verdictid)
			  ->execute();						
		   }	        
		   else {
				$last_id = db_insert('expert_verdict')
		  		->fields(array(
		   			 'filename' => $expertname.'_专家评审文件',
		   			 'url' => $saveurl,
		   			 'file_managed_id' =>  $fid,
		   			 'expert_info_id' => $user->uid,
		   			 'apply_id' => $values['bid'],
		   			 'guiding_fund_id' => $guiding_fund_id,
		   			 'assess'=>$values['assess'],
		   			 'opinion' => $values['opinion'],
		   			 'score_department' => $values['score_department'],
		   			 'score_applyman'=>$values['score_applyman'],
		   			 'score_schema' => $values['score_schema'],
		   			 'state' => $values['state'],
		   			 'timestamp' =>  $_SERVER['REQUEST_TIME'],
		  			))->execute();
		   }
		}		
		else {
			form_set_error('upload',$extension_errors[0]); 
		}
	}
	else{
		if($verdictid>0){
			db_update('expert_verdict')
			  	->fields(array(
			   		 'assess'=>$values['assess'],
		   			 'opinion' => $values['opinion'],
		   			 'score_department' => $values['score_department'],
		   			 'score_applyman'=>$values['score_applyman'],
		   			 'score_schema' => $values['score_schema'],
		   			 'state' => $values['state'],
		   			 'timestamp' =>  $_SERVER['REQUEST_TIME'],
			  	))
			  	->condition('id',$verdictid)
			  	->execute();	
		}		
		else {
			$last_id = db_insert('expert_verdict')
		  		->fields(array(
		   			 'expert_info_id' => $user->uid,
		   			 'apply_id' => $values['bid'],
		   			 'guiding_fund_id' => $guiding_fund_id,
		   			 'assess'=>$values['assess'],
		   			 'opinion' => $values['opinion'],
		   			 'score_department' => $values['score_department'],
		   			 'score_applyman'=>$values['score_applyman'],
		   			 'score_schema' => $values['score_schema'],
		   			 'state' => $values['state'],
		   			 'timestamp' =>  $_SERVER['REQUEST_TIME'],
		  			))->execute();			
		}
	}
	$form_state['redirect'] = 'expertmanage/graded_apply_view/'.$values['bid'];
}

//专家浏览打分结果
//传人专家给分结果id
function expertmanage_graded_apply_viewpage($perid) {
    $page_content = '';
    global $user; 
    $query = "SELECT id ,guiding_fund_id,file_managed_id,filename,url,assess,opinion,score_department,score_applyman,score_schema,timestamp,state FROM " .
           "{expert_verdict} where id = ? ";
    global $user;
    $queryResult = db_query($query, array( $perid));
    $verdictid = '';
	$verdict = '';
	foreach ($queryResult as $verdict ) {
		if($verdict->id>0){
			$verdictid = $verdict->id;
		}
	}
	if($verdictid>0){
		if(user_access('create experts information')){
	    	$page_content .= l('查看评分列表','expertmanage/graded/'.$verdict->guiding_fund_id) . '<br />'. '<br />';	
	    	$page_content .= l('切换成编辑模式','expertmanage/graded_apply/'.$perid) . '<br />'. '<br />'; 
		}
		else{
			$page_content .= l('查看评分列表','expertmanage/all_graded_fund_view/'.$verdict->guiding_fund_id) . '<br />'. '<br />';	
		}
		if($verdict->filename!=''){
			$page_content .= '<h5>审批材料下载:</h5>'.l($verdict->filename, 'http://' .$_SERVER['HTTP_HOST'].'/drupal/sites/default/files/'.$verdict->url).'<br />'.'<br />';
		}		
		$page_content .= '<h5>管理机构得分:</h5>'.$verdict->score_department.'<br />'.'<br />';
		$page_content .= '<h5>发起人得分:</h5>'.$verdict->score_applyman.'<br />'.'<br />';
		$page_content .= '<h5>运营方案得分:</h5>'.$verdict->score_schema.'<br />'.'<br />';
		$page_content .= '<h5>综合评价:</h5>'.$verdict->assess.'<br />'.'<br />';
	    $page_content .= '<h5>推荐意见:</h5>'.$verdict->opinion.'<br />'.'<br />';
		$page_content .= '<h5>评分时间: </h5>'. format_date($verdict->timestamp, 'custom', 'D, Y-m-d').'<br />'.'<br />';
		if($verdict->state == 1)
			$page_content .= '<h5>已提交该评分结果</h5>'.'<br />'.'<br />';
		else if($verdict->state == 0)
			$page_content .= '<h5>尚未提交该评分结果</h5>'.'<br />'.'<br />';
    }
  else {
    $page_content .= "对不起！您没有对该项做过评分.".'<br>'.'<br>';
  }

  return $page_content;
}

//对应申报材料所有专家评分结果列表
//传人评审材料id
function expertmanage_allgraded_apply_viewpage($apply_id) {
    	
  $html = l('返回基金列表','expertmanage/graded_result/fundlist') . '<br />'. '<br />'; 
  $header = array(
      array('data' => '专家名称'),
      array('data' => '管理机构得分', 'field' => 'score_department'),
      array('data' => '发起人得分', 'field' => 'score_applyman'),
      array('data' => '运营方案得分', 'field' => 'score_schema'),
      array('data' => '推荐意见', 'field' => 'opinion'),
      array('data' => '查看详情'),
      );
  $query = "SELECT guiding_fund_id FROM " .
           "{apply_file_info} where id = ?";
  $funds_list = db_query($query, array($apply_id));	
  $guiding_fund_id = '';
  foreach ($funds_list as $fund) {
      $guiding_fund_id = $fund->guiding_fund_id;
  }
  
  $query = db_select('expert_verdict', 'n')
      ->extend('PagerDefault') //Pager Extender
      ->limit(15)//10 results per page
      ->extend('TableSort')//Sorting Extender
      ->orderByHeader($header)//Field to sort on is picked from $header
      ->fields ('n', array (
      'id',
      'score_department',
      'score_applyman',
      'score_schema',
      'opinion',
      'expert_info_id',
      ))
	  ->condition('apply_id', $apply_id,'=')
	  ->condition('state', 1,'=')
	  ;
  
  $results = $query
      ->execute();

  $rows = array();
  $finish_expertlist = '';
  foreach ($results as $node) {
         $query = "SELECT id, name FROM " .
           "{expert_info} where userid = ? ";
		 $expert_list = db_query($query, array($node->expert_info_id));	
		 $current_expertid = '';
		 $current_expertname = '';
		 foreach ($expert_list as $expert) {
		      $current_expertid = $expert->id;
			  $current_expertname = $expert->name;
		  }	
		 $finish_expertlist .= $current_expertid .',';
		  $rows[] = array(
	      'data' => array(
	        l($current_expertname, 'expertmanage/list/'. $current_expertid),
	        $node->score_department,
	        $node->score_applyman,
	        $node->score_schema,
	        $node->opinion,
	        l('详细评审结果', 'expertmanage/graded_apply_view/'.  $node->id),
	      )
	      );
  }
  $query = "SELECT experts_list FROM " .
           "{guiding_fund_info} where id = ?";
  $experts_list = db_query($query, array($guiding_fund_id));	
  $experts = array();
  foreach ($experts_list as $expert) {
      $experts = explode(',',$expert->experts_list);
  }
  $finish_experts = explode(',',$finish_expertlist);
  foreach ($experts as $expert) {
  	if(!in_array($expert,$finish_experts, TRUE)){
  		$query = "SELECT id, name FROM " .
           "{expert_info} where id = ? ";
		$expert_list = db_query($query, array($expert));
		$current_expertid = '';
		$current_expertname = '';
		foreach ($expert_list as $expert) {
		      $current_expertid = $expert->id;
			  $current_expertname = $expert->name;
		}		
		if($current_expertid>0){
			$rows[] = array(
	      'data' => array(
	        l($current_expertname, 'expertmanage/list/'. $current_expertid),
	        '',
	        '',
	        '',
	        '',
	        '尚未提交评分结果',
	      )
	      );
		}
  		
  	}
  }
  $html .= theme('table', 
      array(
            'header' => $header,
            'rows'=>$rows,
            //'caption' => '反馈意见列表',//Optional Caption for the table
            'sticky' => TRUE,//Optional to indicate whether the table headers should be sticky
            'empty' => '没有专家评分结果',//Optional empty text for the table if resultset is empty
      )
      );
  $html .= theme('pager',
      array(
            'tags' => array()
      )
      );
  return ($html); 
}

//对应基金所有申报材料平均专家评分结果列表
//传人基金id
function expertmanage_allgraded_fund_viewpage($fundid){

 $html = l('返回基金列表','expertmanage/graded_result/fundlist') . '<br />'. '<br />'; 
  $query = "SELECT id, name FROM " .
           "{guiding_fund_info} where id = ?";
  $queryResult = db_query($query, array($fundid));
  foreach($queryResult as $result){
  	$html .= '当前基金：' . '&nbsp;&nbsp;'. $result->name.'<br><br>';
  }
 $header = array(
      array('data' => '申报人名称', 'field' => 'apply_name', 'sort' => 'desc'),
      array('data' => '管理机构得分', 'field' => 'score_department'),
      array('data' => '发起人得分', 'field' => 'score_applyman'),
      array('data' => '运营方案得分', 'field' => 'score_schema'),
      array('data' => '总分平均', 'field' => 'timestamp'),
      array('data' => '操作', 'field' => 'setscore'),
      );
  $query = "SELECT to_graded_list FROM " .
           "{guiding_fund_info} where id = ?";
  $company_list = db_query($query, array($fundid));	
  $companys = array();
  foreach ($company_list as $company) {
      $companys = explode(',',$company->to_graded_list);
  }
  
  $query = db_select('apply_file_info', 'n')
      ->extend('PagerDefault') //Pager Extender
      ->limit(15)//10 results per page
      ->extend('TableSort')//Sorting Extender
      ->orderByHeader($header)//Field to sort on is picked from $header
      ->fields ('n', array (
      'id',
      'apply_name',
      ))
	  ->condition('guiding_fund_id', $fundid,'=')
	  ->condition('type', 1,'=')
	  ;
  $results = $query
      ->execute();
  global $user;
  $rows = array();
  $average_score_department = 0.0;
  $average_score_applyman = 0.0;
  $average_score_schema = 0.0;
  $count = 0;
  foreach ($results as $node) {
  	if(in_array($node->id,$companys, TRUE)&&$companys!=NULL){
         $query = "SELECT id, score_department, score_applyman, score_schema FROM " .
           "{expert_verdict} where apply_id = ?";
		 $verdict_list = db_query($query, array($node->id));	
		 foreach ($verdict_list as $verdict) {
		      $count += 1;
			  $average_score_department += $verdict->score_department;
		 	  $average_score_applyman += $verdict->score_applyman;
		 	  $average_score_schema += $verdict->score_schema;
		  }	
		  if($count){
		  	$average_score_department /= $count;
		    $average_score_applyman /= $count;
		    $average_score_schema /= $count;
		  }
		  $title = '';
		 
 		  $title .= l('查看详细评分','expertmanage/all_graded_apply_view/'.$node->id) ;  
		  $rows[] = array(
	      'data' => array(
	        l($node->apply_name, 'applyfile/list/'. $node->id),
	        $average_score_department,
	        $average_score_applyman,
	        $average_score_schema,
	        $average_score_department+$average_score_applyman+$average_score_schema,
	        $title,
	      )
	      );
	}
  }
  $html .= theme('table', 
      array(
            'header' => $header,
            'rows'=>$rows,
            //'caption' => '反馈意见列表',//Optional Caption for the table
            'sticky' => TRUE,//Optional to indicate whether the table headers should be sticky
            'empty' => '没有申报人评分结果',//Optional empty text for the table if resultset is empty
      )
      );
  $html .= theme('pager',
      array(
            'tags' => array()
      )
      );
  return ($html); 
}

//选择基金进入专家评审结果查看
function expertmanage_gradedresult_fundlist_page() {
 $html = ''; 
 global $user;
 $query = "SELECT id FROM " .
           "{expert_info} where userid = ?";
 $experts_list = db_query($query, array($user->uid));	
 $current_expertid = '';
 foreach ($experts_list as $expert) {
      $current_expertid = $expert->id;
  }		   
		   
 $header = array(
      array('data' => '基金名称', 'field' => 'name', 'sort' => 'desc'),
      array('data' => '负责人', 'field' => 'principal_name'),
      array('data' => '电话', 'field' => 'phone'),
      array('data' => '邮箱', 'field' => 'mail'),
      array('data' => '成立时间', 'field' => 'timestamp'),
      array('data' => '评审意见查看', 'field' => 'expert_graded'),
      );
  
  $query = db_select('guiding_fund_info', 'n')
      ->extend('PagerDefault') //Pager Extender
      ->limit(15)//10 results per page
      ->extend('TableSort')//Sorting Extender
      ->orderByHeader($header)//Field to sort on is picked from $header
      ->fields ('n', array (
      'id',
      'name',
      'principal_name',
      'phone',
      'mail',
      'timestamp',
      'experts_list',
      ));
  $results = $query
      ->execute();

  $rows = array();
  foreach ($results as $node) {	  
	  $rows[] = array(
	      'data' => array(
	        l($node->name, 'guidingfund/list/'. $node->id),
	        $node->principal_name,
	        $node->phone,
	        $node->mail,
	        format_date($node->timestamp, 'custom', 'D, Y-m-d'),
	        l('评审意见详情', 'expertmanage/all_graded_fund_view/'. $node->id),
	      )
	  );
  }
  
  $html .= theme('table', 
      array(
            'header' => $header,
            'rows'=>$rows,
            //'caption' => '反馈意见列表',//Optional Caption for the table
            'sticky' => TRUE,//Optional to indicate whether the table headers should be sticky
            'empty' => '没有基金信息',//Optional empty text for the table if resultset is empty
      )
      );
  $html .= theme('pager',
      array(
            'tags' => array()
      )
      );
  return ($html); 
}



